package org.callcenterkata;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.callcenterkata.dao.IToolSearchDao;
import org.callcenterkata.dao.Tool;
import org.callcenterkata.dao.ToolSearchDao;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ToolSearchAction extends ActionSupport {

	private IToolSearchDao toolSearchDao = new ToolSearchDao();
	private String name;
	private List<Tool> tools = new ArrayList<Tool>();
	private String nickname;

	public List<Tool> getTools() {
		return tools;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	@Override
	public String execute() throws Exception {
		if (StringUtils.isNotBlank(name)) {
			tools = toolSearchDao.findToolsByName(name);
		} else if (StringUtils.isNotBlank(nickname)) {
			tools = toolSearchDao.findToolsByNickname(nickname);
		}
		return SUCCESS;
	}
	
	protected void setToolSearchDao(IToolSearchDao toolSearchDao) {
		this.toolSearchDao = toolSearchDao;
	}
}
